﻿namespace _4_流控制;

internal enum Color
{
    Red,
    Green,
    Blue,
    Brown,
    Yellow,
    Pink,
    Orange
}

internal class Program
{
    private static void Main(string[] args)
    {
        #region 1_switch-case-when-default

        //Console.Write("Enter your age: ");

        //var input = Console.ReadLine();

        //var age = Int32.Parse(input.Trim());

        //switch (age)
        //{
        //    // 这个when是在7.0版本中新加入的，用来实现条件判断
        //    case var myAge when myAge < 0:
        //        Console.WriteLine("Age cannot be a negative value");
        //        break;

        //    case var myAge when myAge > 130:
        //        Console.WriteLine("This is an unlikely high age");
        //        break;

        //    default:
        //        Console.WriteLine("The entered age is {0}", age);
        //        break;
        //}

        //// 使用枚举作为匹配表达式
        //var r = new Random().Next(0, 7);
        //var color = (Color)r;
        //switch (color)
        //{
        //    case Color.Red:
        //        Console.WriteLine("The color is red");
        //        break;

        //    case Color.Green:
        //        Console.WriteLine("The color is green");
        //        break;

        //    case Color.Blue:
        //        Console.WriteLine("The color is blue");
        //        break;

        //    case Color.Brown:
        //        Console.WriteLine("The color is brown");
        //        break;

        //    case Color.Yellow:
        //        Console.WriteLine("The color is yellow");
        //        break;

        //    case Color.Pink:
        //        Console.WriteLine("The color is pink");
        //        break;

        //    case Color.Orange:
        //        Console.WriteLine("The color is orange");
        //        break;

        //    default:
        //        Console.WriteLine("The color is unknown.");
        //        break;
        //}

        #endregion

        #region 2_switch表达式(大白话, 语法更加简洁了)

        //Console.WriteLine("Enter your age: ");
        //var age = int.Parse(Console.ReadLine());
        //string msg = age switch
        //{
        //    <18 => "You are a child.",
        //    18 => "You are a teenager.",
        //    >18 and <50 => "You are an adult.",
        //    _ => "You are an old man."
        //};
        //Console.WriteLine(msg);

        #endregion
    }
}